package com.hnkywl.sts.dao.base;

import com.hnkywl.sts.service.sys.YgService;
import org.apache.commons.lang3.StringUtils;

/**
 * Created with IntelliJ IDEA.
 * User: ZHUCHG
 * Date: 13-5-8
 * Time: 下午9:10
 * To change this template use File | Settings | File Templates.
 */
public class RegionForBgDao {
    public static String createSQLDataRegion(String joinStr, String alias, boolean allowByPerson) {
        alias = StringUtils.isEmpty(alias) ? "" : alias + ".";
        joinStr = StringUtils.isEmpty(joinStr) ? "" : joinStr + " and ";
        String regionSql = "";
        int cxfw = YgService.getCurrentYgCxfw();
        if (cxfw == 3 && !allowByPerson)
            cxfw = 2;
        switch (YgService.getCurrentYgCxfw()) {
            case 0:
                regionSql += " {0} 1=1";
                break;
            case 1:
                regionSql += " {0} {1}createorgan_id =" + YgService.getCurrentYgZgGsId();
                break;
            case 2:
                regionSql += " {0} {1}createdepartment_id =" + YgService.getCurrentYgGsId();
                break;
            case 3:
                regionSql += " {0} {1}createuser_id =" + YgService.getCurrentYg().getId()
                        + " and {1}createdepartment_id =" + YgService.getCurrentYgGsId();
                break;
        }

        return regionSql.replace("{0}", joinStr).replace("{1}", alias);
    }

    public static String SQLDataRegion(String st) {
        String sql = " where ";
        switch (YgService.getCurrentYgCxfw()) {
            case 0:
                sql += " 1=1 ";
                break;
            case 1:
                sql += st+".createorgan_id =" + YgService.getCurrentYgZgGsId();
                break;
            case 2:
                sql += st+".createdepartment_id =" + YgService.getCurrentYgGsId();
                break;
            case 3:
                sql += st+".createuser_id =" + YgService.getCurrentYg().getId()
                        + " and "+st+".createdepartment_id =" + YgService.getCurrentYgGsId();
                break;
        }

        return sql;
    }

}
